package battle
{
	import battle.commands.CommandQueue;
	import battle.test.TestStage;
	
	import data.HeroInfo;
	import data.PlayerInfo;
	import data.SoldierInfo;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import map.MapInfo;
	import map.MapView;
	
	import utils.StageReferance;
	
	public class BattleScene extends Sprite
	{
		private var _map:MapView;
		public function BattleScene()
		{
			super();
		}
		
		private var _gameInfo:GameInfo;
		public function enter(gameInfo:GameInfo):void
		{
			_gameInfo = gameInfo;
			
		}
		
		public function runTest():void
		{
			_gameInfo = new GameInfo();
			_gameInfo.mapInfo = new MapInfo();
			_gameInfo.mapInfo.id = 'map001';
			_map = new MapView(_gameInfo.mapInfo,StageReferance.stageWidth,StageReferance.stageHeight);
			_map.addEventListener(Event.COMPLETE,onMapComplete);
			_map.addEventListener(MouseEvent.CLICK,onMapClick);
			addChild(_map);
			var humanPlayer:PlayerInfo = new PlayerInfo();
			humanPlayer.beginChanges();
			humanPlayer.id = 0;
			humanPlayer.nickname = 'herman';
			var hhero:HeroInfo = new HeroInfo();
			hhero.beginChanges();
			hhero.actions='stand';
			hhero.avatar='hero001';
			hhero.hp=100;
			hhero.commitChanges();
			humanPlayer.addSoldier(hhero);
			humanPlayer.commitChanges();
			
			
			var aiPlayer:PlayerInfo = new PlayerInfo();
			aiPlayer.beginChanges();
			aiPlayer.id = 1;
			aiPlayer.nickname = 'herman';
			var ahero:HeroInfo = new HeroInfo();
			ahero.beginChanges();
			ahero.actions='stand';
			ahero.avatar='hero001';
			ahero.hp=100;
			ahero.commitChanges();
			humanPlayer.addSoldier(ahero);
			aiPlayer.commitChanges();
			
			_gameInfo.addPlayer(humanPlayer);
			_gameInfo.addPlayer(aiPlayer);
			
			var testStage:TestStage = new TestStage();
//			testStage.run(_gameInfo);
			addEventListener(Event.ENTER_FRAME,tick);
		}
		
		private function onMapClick(event:MouseEvent):void
		{
			_map.viewAt(new Point(event.localX,event.localY),1,true);
		}
		
		public function tick(event:Event):void
		{
			CommandQueue.Instance.excute();
			_map.update();
		}
		
		
		public function addLiving(living:DisplayObject):void
		{
			_map.addLiving(living);
		}
		
		private function onMapComplete(event:Event):void
		{
			
		}
		
		public function get info():GameInfo
		{
			return _gameInfo;
		}
		
		
	}
}